<?php
loadTemp("admin/models/class/classheader.php");
?>
<script type="text/javascript">
$(document).ready(function(){
	loadAdminTopItem();
	activeAdminTopItem("s_c_addclass");
});
</script>
<?php checkAdminPermission("admin.class.add_class","admin.class.*");?>
<!-- Start -->
<script type="text/javascript">
$(document).ready(function(){
	bindAjaxForm($("#form_add_class"),s_addclass_onSuccess,s_addclass_onError,"admin_di");
	$(".s_master_selecter").hide();
});
function s_addclass_onSuccess(data){
	console.log(data);
	s_addclass_operatedone(data.code,data.message,data.data);
}
function s_addclass_onError(data){
	console.log(data);
	s_addclass_operatedone(-101,"服务器返回了未知的数据，请上报管理员",data.responseText);
}
function s_addclass_operatedone(id,message,data){
	if(id==-101){
		showMessage("s_addclass_message",-101,message+"<br><br><pre>"+data+"</pre>");
		return;
	}
	if(id!=0&&id!=3){
		showMessage("s_addclass_message",id,message);
	}
	if(id==0){
		showMessage("s_addclass_message",id,message);
	}
	if(data.op=="reset"){
		$(".s_master_searcher").show();
		$(".s_master_selecter").hide();
		$("#form_add_class").find("input").val("");
		$(".s_master_selecter").find(".s_master_headImage").attr("src","");
		$(".s_master_selecter").find(".s_master_name").html("");
		$(".s_master_selecter").find(".s_master_uid").attr("value","");
		$("#form_add_class").addClass("error");
	}
	if(data.op=="master_search"){
		$(".s_master_searcher").hide();
		$(".s_master_selecter").show();
		$(".s_master_selecter").find(".s_master_headImage").attr("src",data.card.head_image_path);
		$(".s_master_selecter").find(".s_master_name").html(data.card.name);
		$(".s_master_selecter").find(".s_master_uid").attr("value",data.card.uid);
		$("#form_add_class").removeClass("error");
	}
}
function s_doc_search(a){
	if(a==""){
		return;
	}
	ajaxRequest("account="+a,"admin.php?mod=class&ajax=true&op=search_master",s_addclass_onSuccess,s_addclass_onError);
	
}
</script>
<div class="s_admin_in_container">
	<h2 class="ui dividing header">添加班级</h2>
	<div class="ui message">
		<div class="header">小提示</div>
		<ul class="list">
			<li>这里是班级添加模块</li>
			<li>你可以在这里添加班级</li>
		</ul>
	</div>
	<div class="ui message hidden" id="s_addclass_message"></div>
	<form class="ui form" url="admin.php?mod=class&ajax=true&op=add_class" id="form_add_class">
		<div class="field">
			<label>班级id</label>
			<div class="field">
				<input id="classid" type="text" name="classid" placeholder="班级id不能和现有的重复，推荐年号+班级号，诸如1701（17届1班）">
			</div>
			<label>展示名称</label>
			<div class="field">
				<input id="displayname" type="text" name="displayname" placeholder="班级的展示名称，诸如 2017级1班">
			</div>
			<label>班级介绍</label>
			<div class="field">
				<input id="introduce" type="text" name="introduce" placeholder="班级介绍">
			</div>
			<label>入学年份</label>
			<div class="field">
				<input id="admission_year" type="text" name="admission_year" placeholder="入学年份的四位数字，例：2019">
			</div>
			<div class="ui action fluid input s_master_searcher">
				<div class="ui left icon input">
					<input type="text" name="account" id="master_account" placeholder="请输入班主任的账号" onBlur="s_doc_search($('#master_account').val());">
					<i class="users icon"></i>
				</div>
			</div>
			<div class="field inline s_master_selecter" style="display: none;">
				<label>班主任：</label>
				<input class="s_master_uid" name="master" type="hidden">
				<img class="ui avatar image s_master_headImage">
				<span class="s_master_name"></span>
			</div>
		</div>
		<div class="ui error message"></div>
		<button type="submit" class="ui submit button" tabindex="0">提交</button>
	</form>
</div>
